package br.com.positrot.test;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import br.com.positrot.model.dao.UsuarioDAO;
import br.com.positrot.model.dao.exception.DaoException;
import br.com.positrot.model.vo.UsuarioVO;

public class RedefinicaoDeSenha {
	
	public static void main(String... args) {
		
		try {
			UsuarioVO usuarioVO = (UsuarioVO) new UsuarioDAO().obterUsuarioPorId(3);

			
			MessageDigest md;
			
				
			try {
				
				md = MessageDigest.getInstance("SHA");
				md.update(usuarioVO.getLogin().toLowerCase().getBytes());
				BigInteger hash = new BigInteger(1, md.digest());

				usuarioVO.setSenhaExpirada(false);
				usuarioVO.setSenha(hash.toString(16));
				new UsuarioDAO().alterar(usuarioVO);

				if (usuarioVO.getSenha().equals(hash.toString(16))) {
					System.out.println(true);
				} else {
					System.out.println(false);
				}

			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
		       
	
		} catch (DaoException e) {
			
			e.printStackTrace();
		}
	}

}
